const BaseIpcHandler = require('../BaseIpcHandler');

class PeekQueueHandler extends BaseIpcHandler {
    async handle(event, params) {
        // 解析参数
        const timestamp = new Date().toISOString();
        // console.log(`>> [${timestamp}] PeekQueueHandler params = `, params);
        const { task_id, from_index, num } = params;

        // 业务逻辑
        let result = this.app.queue.peek(task_id, from_index, num);
        result = { code: 0, msg: result };
        // console.log('PeekQueue result = ', result);

        // 返回结果
        if (event.from === 'localserver') {
            event.resp.send(result);
        } else {
            return result;
        }
    }
}

module.exports = PeekQueueHandler;
